<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="LeetCode,">










<meta name="description" content="1. 有序数组的 Two SumLeetCode 167 Input: numbers 有序数组,target 需要求和的值Output: index1,index2  两个值的下标，注意从1开始 题目描述：在有序数组中寻找两个数，使之和为 target 使用双指针，一个指针指向较小的元素，一个指针指向较大的元素。小指针从头开始往后遍历，大指针从尾开始往前遍历。  如果两个指针指向的元素和为 ta">
<meta name="keywords" content="LeetCode">
<meta property="og:type" content="article">
<meta property="og:title" content="双指针">
<meta property="og:url" content="https://xiver.gitee.io/2019/06/28/双指针/index.html">
<meta property="og:site_name" content="Condi">
<meta property="og:description" content="1. 有序数组的 Two SumLeetCode 167 Input: numbers 有序数组,target 需要求和的值Output: index1,index2  两个值的下标，注意从1开始 题目描述：在有序数组中寻找两个数，使之和为 target 使用双指针，一个指针指向较小的元素，一个指针指向较大的元素。小指针从头开始往后遍历，大指针从尾开始往前遍历。  如果两个指针指向的元素和为 ta">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-06-27T23:19:20.032Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="双指针">
<meta name="twitter:description" content="1. 有序数组的 Two SumLeetCode 167 Input: numbers 有序数组,target 需要求和的值Output: index1,index2  两个值的下标，注意从1开始 题目描述：在有序数组中寻找两个数，使之和为 target 使用双指针，一个指针指向较小的元素，一个指针指向较大的元素。小指针从头开始往后遍历，大指针从尾开始往前遍历。  如果两个指针指向的元素和为 ta">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://xiver.gitee.io/2019/06/28/双指针/">





  <title>双指针 | Condi</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Condi</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://xiver.gitee.io/2019/06/28/双指针/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Condi">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Condi">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">双指针</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-06-28T06:17:04+08:00">
                2019-06-28
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="1-有序数组的-Two-Sum"><a href="#1-有序数组的-Two-Sum" class="headerlink" title="1. 有序数组的 Two Sum"></a>1. 有序数组的 Two Sum</h1><p>LeetCode 167</p>
<p>Input: numbers 有序数组,target 需要求和的值<br>Output: index1,index2  两个值的下标，注意从1开始</p>
<p>题目描述：在有序数组中寻找两个数，使之和为 target</p>
<p>使用双指针，一个指针指向较小的元素，一个指针指向较大的元素。小指针从头开始往后遍历，大指针从尾开始往前遍历。</p>
<ul>
<li>如果两个指针指向的元素和为 target 则得到了要求的结果</li>
<li>如果 sum &gt; target 说明结果大了，大指针需要前移</li>
<li>如果 sum &lt; target 说明结果小了，小指针需要后移</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @param &#123;number[]&#125; numbers</span></span><br><span class="line"><span class="comment"> * @param &#123;number&#125; target</span></span><br><span class="line"><span class="comment"> * @return &#123;number[]&#125;</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> twoSum = <span class="function"><span class="keyword">function</span> (<span class="params">numbers, target</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">let</span> p1 = <span class="number">0</span>, p2 = numbers.length - <span class="number">1</span></span><br><span class="line">  <span class="keyword">while</span> (p1 &lt; p2) &#123;</span><br><span class="line">    <span class="keyword">if</span> (numbers[p1] + numbers[p2] === target) <span class="keyword">return</span> [p1 + <span class="number">1</span>, p2 + <span class="number">1</span>]</span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">if</span> (numbers[p1] + numbers[p2] &lt; target) p1++</span><br><span class="line">    <span class="keyword">else</span> p2--</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h1 id="2-两数平方和"><a href="#2-两数平方和" class="headerlink" title="2. 两数平方和"></a>2. 两数平方和</h1><p>LeetCode 633</p>
<p>Input: 5<br>Output: True</p>
<p>题目描述：判断一个数是否是两个数的平方和</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> judgeSquareSum = <span class="function"><span class="keyword">function</span> (<span class="params">c</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">let</span> p1 = <span class="number">0</span>, p2 = <span class="built_in">parseInt</span>(<span class="built_in">Math</span>.sqrt(c))</span><br><span class="line">  <span class="keyword">while</span> (p1 &lt;= p2) &#123;</span><br><span class="line">    <span class="keyword">if</span> (p1 * p1 + p2 * p2 === c) <span class="keyword">return</span> <span class="literal">true</span></span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">if</span> (p1 * p1 + p2 * p2 &gt; c) p2--</span><br><span class="line">    <span class="keyword">else</span> p1++</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="literal">false</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h1 id="3-反转字符串中的元音字母"><a href="#3-反转字符串中的元音字母" class="headerlink" title="3. 反转字符串中的元音字母"></a>3. 反转字符串中的元音字母</h1><p>LeetCode 345</p>
<p>Input: “LeetCode”<br>Output: “LeoCede”</p>
<p>解题思路：使用双指针指向待反转的两个元音字母，一个指针从头遍历，一个指针从尾遍历。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> reverseVowels = <span class="function"><span class="keyword">function</span> (<span class="params">s</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">const</span> VOWELS = &#123; <span class="string">'a'</span>: <span class="number">1</span>, <span class="string">'e'</span>: <span class="number">1</span>, <span class="string">'i'</span>: <span class="number">1</span>, <span class="string">'o'</span>: <span class="number">1</span>, <span class="string">'u'</span>: <span class="number">1</span>, <span class="string">'A'</span>: <span class="number">1</span>, <span class="string">'E'</span>: <span class="number">1</span>, <span class="string">'I'</span>: <span class="number">1</span>, <span class="string">'O'</span>: <span class="number">1</span>, <span class="string">'U'</span>: <span class="number">1</span> &#125;</span><br><span class="line">  <span class="keyword">const</span> arr = s.split(<span class="string">''</span>)</span><br><span class="line">  <span class="keyword">let</span> i = <span class="number">0</span>, j = arr.length - <span class="number">1</span></span><br><span class="line">  <span class="keyword">while</span> (i &lt; j) &#123;</span><br><span class="line">    <span class="keyword">if</span> (VOWELS[arr[i]] &amp;&amp; VOWELS[arr[j]]) &#123;</span><br><span class="line">      [arr[i], arr[j]] = [arr[j], arr[i]]</span><br><span class="line">      i++</span><br><span class="line">      j--</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (VOWELS[arr[i]]) j--</span><br><span class="line">    <span class="keyword">else</span> i++</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> arr.join(<span class="string">''</span>)</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h1 id="4-回文字符串"><a href="#4-回文字符串" class="headerlink" title="4. 回文字符串"></a>4. 回文字符串</h1><p>LeetCode 680</p>
<p>Input: “abca”<br>Output: true</p>
<p>题目描述：可以删除一个字符，判断是否可以构成回文串</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> validPalindrome = <span class="function"><span class="keyword">function</span> (<span class="params">s</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">let</span> i = <span class="number">0</span>, j = s.length<span class="number">-1</span></span><br><span class="line">  <span class="keyword">while</span> (i &lt; j) &#123;</span><br><span class="line">    <span class="keyword">if</span> (s[i] !== s[j]) &#123;</span><br><span class="line">      <span class="keyword">return</span> judge(s, i + <span class="number">1</span>, j) || judge(s, i, j - <span class="number">1</span>)</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      i++</span><br><span class="line">      j--</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="literal">true</span></span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> judge = <span class="function">(<span class="params">s, i, j</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">while</span> (i &lt; j) &#123;</span><br><span class="line">    <span class="keyword">if</span> (s[i] !== s[j]) &#123;</span><br><span class="line">      <span class="keyword">return</span> <span class="literal">false</span></span><br><span class="line">    &#125;</span><br><span class="line">    i++</span><br><span class="line">    j--</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="literal">true</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="5-归并两个有序数组"><a href="#5-归并两个有序数组" class="headerlink" title="5. 归并两个有序数组"></a>5. 归并两个有序数组</h1><p>LeetCode 88</p>
<p>Input:<br>nums1 = [1,2,3,0,0,0], m = 3<br>nums2 = [4,5,6], n = 3</p>
<p>Output:<br>[1,2,3,4,5,6]</p>
<p>题目描述：把结果归并在第一个数组上</p>
<p>需要从尾部开始遍历，不然结果会覆盖未进行归并的值。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> merge = <span class="function"><span class="keyword">function</span> (<span class="params">nums1, m, nums2, n</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">let</span> p1 = m - <span class="number">1</span>, p2 = n - <span class="number">1</span>, mergeIndex = m + n - <span class="number">1</span></span><br><span class="line">  <span class="keyword">while</span> (p1 &gt;= <span class="number">0</span> || p2 &gt;= <span class="number">0</span>) &#123;</span><br><span class="line">    <span class="keyword">if</span> (p1 &lt; <span class="number">0</span>) &#123;</span><br><span class="line">      nums1[mergeIndex--] = nums2[p2--]</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (p2 &lt; <span class="number">0</span>) &#123;</span><br><span class="line">      nums1[mergeIndex--] = nums1[p1--]</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (nums2[p2] &gt;= nums1[p1]) &#123;</span><br><span class="line">      nums1[mergeIndex--] = nums2[p2--]</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      nums1[mergeIndex--] = nums1[p1--]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h1 id="6-判断链表是否存在环"><a href="#6-判断链表是否存在环" class="headerlink" title="6. 判断链表是否存在环"></a>6. 判断链表是否存在环</h1><p>LeetCode 141</p>
<p>使用双指针，一个指针一次移动一个节点，一个一次移动两个节点，如果存在环，则两个指针一定会相遇。<br>PS: 起始时不能使两个指针指向同一个节点，一前一后不会出问题。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> hasCycle = <span class="function"><span class="keyword">function</span> (<span class="params">head</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">if</span> (head === <span class="literal">null</span>) <span class="keyword">return</span> <span class="literal">false</span></span><br><span class="line">  <span class="keyword">let</span> p1 = head, p2 = head.next</span><br><span class="line">  <span class="keyword">while</span> (p1 !== <span class="literal">null</span> &amp;&amp; p2 !== <span class="literal">null</span> &amp;&amp; p2.next !== <span class="literal">null</span>) &#123;</span><br><span class="line">    <span class="keyword">if</span> (p1 === p2) <span class="keyword">return</span> <span class="literal">true</span></span><br><span class="line">    p1 = p1.next</span><br><span class="line">    p2 = p2.next.next</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="literal">false</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h1 id="7-最长子序列"><a href="#7-最长子序列" class="headerlink" title="7. 最长子序列"></a>7. 最长子序列</h1><p>LeetCode 524</p>
<p>Input:<br>s = “abpcplea”, d = [“ale”,”apple”,”monkey”,”plea”]</p>
<p>Output:<br>“apple”</p>
<p>题目描述：删除 s 中的一些字符，使之能构成 d 列表中的一个字符串，找出能构成的最长字符串，如果字符串长度相同，则取字典序最小的。</p>
<p>通过删除 s 中的一些字符获得字符串 t，可以认为 t 是 s 的子串序列，我们可以用双指针判断一个字符串是否是另一个字符串的子序列</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> findLongestWord = <span class="function"><span class="keyword">function</span> (<span class="params">s, d</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">let</span> longestCode = <span class="string">''</span></span><br><span class="line"></span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">let</span> cur <span class="keyword">of</span> d) &#123;</span><br><span class="line">    <span class="keyword">const</span> l1 = longestCode.length, l2 = cur.length</span><br><span class="line">    <span class="keyword">if</span> (l1 &gt; l2 || (l1 === l2 &amp;&amp; cur &gt; longestCode))</span><br><span class="line">      <span class="keyword">continue</span></span><br><span class="line">    <span class="keyword">if</span> (isSubStr(s, cur)) &#123;</span><br><span class="line">      longestCode = cur</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> longestCode</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> isSubStr = <span class="function">(<span class="params">s, target</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">let</span> i = <span class="number">0</span>, j = <span class="number">0</span></span><br><span class="line">  <span class="keyword">while</span> (i &lt; s.length &amp;&amp; j &lt; target.length) &#123;</span><br><span class="line">    <span class="keyword">if</span> (s[i] === target[j]) &#123;</span><br><span class="line">      j++</span><br><span class="line">    &#125;</span><br><span class="line">    i++</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> j === target.length</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/LeetCode/" rel="tag"># LeetCode</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/06/29/排序/" rel="prev" title="排序">
                排序 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Condi</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">5</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#1-有序数组的-Two-Sum"><span class="nav-number">1.</span> <span class="nav-text">1. 有序数组的 Two Sum</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#2-两数平方和"><span class="nav-number">2.</span> <span class="nav-text">2. 两数平方和</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#3-反转字符串中的元音字母"><span class="nav-number">3.</span> <span class="nav-text">3. 反转字符串中的元音字母</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#4-回文字符串"><span class="nav-number">4.</span> <span class="nav-text">4. 回文字符串</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#5-归并两个有序数组"><span class="nav-number">5.</span> <span class="nav-text">5. 归并两个有序数组</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#6-判断链表是否存在环"><span class="nav-number">6.</span> <span class="nav-text">6. 判断链表是否存在环</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#7-最长子序列"><span class="nav-number">7.</span> <span class="nav-text">7. 最长子序列</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Condi</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
